<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2016/7/22
 * Time: 14:44
 */

namespace Mobile\Controller;
use Think\Controller;
use User\Api\UserApi;
use Think\Log;
class CommonAPIController extends Controller
{

    /*
     *请求链接：http://jxc.test.aomai.com.au/orderAPI.php/CommonAPI/adjustPriceLogin
     *调价工具的登录Api
     * 传递参数：
     *username string  用户名
     *pwd string  密码（加密之后的字符串）
     *返回的参数：array resultInfo
     * status int 1成功; 0 错误
     * info  string 返回的提示信息
     * */
    public function adjustPriceLogin(){
        $userName=trim(I('request.username'));
        $pwd=trim(I('request.pwd'));
        Log::record($userName);
        $resultInfo['status']=0;

        if(!empty($userName)&&!empty($pwd)){

            $userInfo=M('ucenter_member')->where(array('username'=>$userName))->field('id,password,status')->find();
            if(is_array($userInfo)&&!empty($userInfo['status'])){
                if($userInfo['password']===$pwd){
                    $resultInfo['status']=1;
                    $resultInfo['info']='登录成功!';
                    $resultInfo['userid']=$userInfo['id'];
                    //记录登录日志
                    $loginInfo['model']='PriceTool';  //模块名
                    $loginInfo['remark']=$userName."在".date('Y-m-d H:i:s')."登录了调价工具";   //备注
                    $userId=$userInfo['id'];  //用户id
                    action_log('user_login','PriceTool',1,$userId,$loginInfo);
                }else{
                    $resultInfo['info']='用户名或密码不正确,请重新输入!';
                }
            }else{
                $resultInfo['info']='用户名或密码不正确,请重新输入!';
            }
        }else{
            $resultInfo['info']='用户名或密码不能为空!';
        }
        $this->ajaxReturn($resultInfo);
    }

    /*
     *请求链接：http://jxc.test.aomai.com.au/orderAPI.php/CommonAPI/adjustPriceLogOut
     *调价工具的注销Api
     * 传递参数：
     *username string  用户名
     *userid int  用户id
     * */
    public function adjustPriceLogOut(){
        $userName=trim(I('request.username',''));       //登录用户名
        $userId=I('request.userid','');    //用户id
        $loginInfo['model']='PriceTool';  //价格调试工具
        $loginInfo['remark'] = $userName . "在" . date('Y-m-d H:i:s') . "退出了调试工具";
        action_log('user_logout', 'PriceTool', 1, $userId,$loginInfo);
    }

}